package com.factory.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class jdkdyincproxy implements InvocationHandler {

    //声明需要代理的对象
    private car car;

    public jdkdyincproxy(car car) {
        this.car = car;
    }

    //获取代理对象
    public Object getTarget(){
        Object object = Proxy.newProxyInstance(car.getClass().getClassLoader(),car.getClass().getInterfaces(),this);
        return object;
    }


    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
      System.out.println("运行先执行的方法--------");
      //执行原来的方法
      Object invoke = method.invoke(car,args);
      System.out.println("业务逻辑后置方法--------");
      return invoke;
    }
}
